package constants

import (
	"hi-jvm/instructions/base"
	"hi-jvm/rtda"
)

/*
 * const系列指令把隐含在操作码中的常用值推入操作数栈顶。
 * 当前定义了15条指令
 */

// 把null引用推入操作数栈顶 指令码：0x01
type ACONST_NULL struct{ base.NoOperandsInstruction }

// 将Double数值0推入操作数栈顶
type DCONST_0 struct{ base.NoOperandsInstruction }

// 将Double数值1推入操作数栈顶
type DCONST_1 struct{ base.NoOperandsInstruction }

type FCONST_0 struct{ base.NoOperandsInstruction }
type FCONST_1 struct{ base.NoOperandsInstruction }
type FCONST_2 struct{ base.NoOperandsInstruction }

// Push int -1 constant 指令码：0x02
type ICONST_M1 struct{ base.NoOperandsInstruction }

// 指令码：0x03
type ICONST_0 struct{ base.NoOperandsInstruction }
// 指令码：0x04
type ICONST_1 struct{ base.NoOperandsInstruction }
// 指令码：0x05
type ICONST_2 struct{ base.NoOperandsInstruction }
// 指令码：0x06
type ICONST_3 struct{ base.NoOperandsInstruction }
// 指令码：0x07
type ICONST_4 struct{ base.NoOperandsInstruction }
// 指令码：0x08
type ICONST_5 struct{ base.NoOperandsInstruction }

// Push long 0 constant 指令码：0x09
type LCONST_0 struct{ base.NoOperandsInstruction }
// 指令码：0x0a
type LCONST_1 struct{ base.NoOperandsInstruction }

func (self *ACONST_NULL) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushRef(nil)
}

func (self *DCONST_0) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushDouble(0.0)
}

func (self *DCONST_1) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushDouble(1.0)
}

func (self *FCONST_0) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushFloat(0.0)
}
func (self *FCONST_1) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushFloat(1.0)
}
func (self *FCONST_2) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushFloat(2.0)
}
func (self *ICONST_M1) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushInt(-1)
}
func (self *ICONST_0) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushInt(0)
}
func (self *ICONST_1) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushInt(1)
}
func (self *ICONST_2) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushInt(2)
}
func (self *ICONST_3) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushInt(3)
}
func (self *ICONST_4) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushInt(4)
}
func (self *ICONST_5) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushInt(5)
}
func (self *LCONST_0) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushLong(0)
}
func (self *LCONST_1) Execute(frame *rtda.Frame) {
	frame.OperandStack.PushLong(1)
}



